package com.redpack.redpost.util.to;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpSession;

public class validaciones {
	
	public validaciones( ){
		
	}
	
	public static String htmlentities(String str) {
		return org.apache.commons.lang.StringEscapeUtils.escapeHtml(str);
	    }

	    public static String quitaLinks(String str) {
		str = str.replaceAll("((http|https|ftp|mailto):\\S+)", "");
		return str;
	    }
	
	public static int getInt(String val, int defval){
		if(null != val && val.matches("^([0-9]+)$") ){
		    return Integer.parseInt(val);
		}   return defval;
	    }
	
	public static boolean isEmail(String email) {
		Pattern ptrn = Pattern.compile("^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@([_a-zA-Z0-9-]+\\.)*[a-zA-Z0-9-]{2,200}\\.[a-zA-Z]{2,6}$");
		Matcher mtch = ptrn.matcher(email);
		return mtch.find();
	    }
	
	public static String stripTags(String str) {
		str = str.replaceAll("<[^>]+>", "");
		return str;
	    }
	
	public static String  idioma( String salida , String idioma ) throws Exception{
		String res = salida ;
		
		if( idioma != null  )
			res = salida +"" + idioma ;
		
		return res ;
		
	}

}
